package example.Brick.IMU;
import com.tinkerforge.BrickIMU;
import com.tinkerforge.IPConnection;

public class ExampleCallback {
	private static final String host = "localhost";
	private static final int port = 4223;
	private static final String UID = "ayQskyoNrCW"; // Change to your UID

	// Note: To make the examples code cleaner we do not handle exceptions.
	// Exceptions you
	// might normally want to catch are described in the documentation
	public static void main(final String args[]) throws Exception {
		final IPConnection ipcon = new IPConnection(); // Create IP connection
		final BrickIMU imu = new BrickIMU(ExampleCallback.UID, ipcon); // Create
																		// device
																		// object

		ipcon.connect(ExampleCallback.host, ExampleCallback.port); // Connect to
																	// brickd
		// Don't use device before ipcon is connected

		// Set period for quaternion callback to 1s
		imu.setQuaternionPeriod(1000);

		// Add and implement quaternion listener
		imu.addQuaternionListener(new BrickIMU.QuaternionListener() {
			@Override
			public void quaternion(final float x, final float y, final float z,
					final float w) {
				System.out.println("x: " + x);
				System.out.println("y: " + y);
				System.out.println("z: " + z);
				System.out.println("w: " + w);
				System.out.println("");
			}
		});

		System.console().readLine("Press key to exit\n");
		ipcon.disconnect();
	}
}
